//
//  COHeHTTP.swift
//  CocoProject
//
//  Created by Ruthless on 2023/8/30.
//

import UIKit
import Moya

let heProvider = MoyaProvider<COHeHTTP>()
enum COHeHTTP {
    case message(id: Int)
    case sq(id: Int, page: Int)
    case qa(id: Int, page: Int)
    case gift(id: Int, count: Int)
    case follo(id: Int)
    case cancelFollo(id: Int)
}

extension COHeHTTP: TargetType {
    var path: String {
        switch self {
        case .message:
            return "/coco/coco589/other/user"
        case .sq:
            return "/coco/coco589/other/page/002"
        case .qa:
            return "/coco/coco589/other/q0002/page"
        case .gift:
            return "/coco/coco589/square/004"
        case .follo:
            return "/coco/coco589/follow/01302/follow"
        case .cancelFollo:
            return "/coco/coco589/follow/01302/cancel/follow"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .message:
            return .get
        case .sq:
            return .post
        case .qa:
            return .post
        case .gift:
            return .get
        case .follo:
            return .get
        case .cancelFollo:
            return .get
        }
    }
    
    var task: Moya.Task {
        var params: [String: Any] = [:]
        switch self {
        case let .message(id):
            params["userId"] = id
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        case let .sq(id, page):
            params["pagSize"] = 20
            params["pagNum"] = page
            params["userId"] = id
        case let .qa(id, page):
            params["pagSize"] = 20
            params["pagNum"] = page
            params["userId"] = id
        case let .gift(id, count):
            params["id"] = id
            params["count"] = count
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        case let .follo(id):
            params["id"] = id
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        case let .cancelFollo(id):
            params["id"] = id
            return .requestParameters(parameters: params, encoding: URLEncoding.default)
        }
        return .requestParameters(parameters: params, encoding: JSONEncoding.default)
    }
    
    
    var headers: [String : String]? {
        var params: [String: String] = [:]
        params["AVS"] = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
        params["OSB"] = "1"
        params["AGKB"] = "H1"
        params["token"] = COUserManager.userInfo?.token
        return params
    }
    
}
